class SelectDialog extends fairygui.GComponent{

    public view: fairygui.GComponent;
    public list:fairygui.GList;
    public bg:fairygui.GImage;

    public stageWidth:number = 600;
    public stageHeight:number = 800;
    
    constructor(){
        super();
        this.view = fairygui.UIPackage.createObject("ui","SelectDialog").asCom;
        this.list = <fairygui.GList>this.view.getChild("list");
        this.bg = <fairygui.GImage>this.view.getChild("n5");
        this.list.removeChildrenToPool();
        this.addChild(this.view);

        this.list.addEventListener(fairygui.ItemEvent.CLICK,(evt)=>{
            let index:number = evt.itemObject.data;
            this.dispatchEventWith(EVENT.DIALOG_SELECT, false, index)
        } ,this)
    }

    public show():void
    {
        this.visible = true;
        this.x = (this.stageWidth - this.view.width * this.scaleX) / 2;
        this.y = (this.stageHeight - this.view.height* this.scaleY) / 2;
    }
    public hide():void
    {
        this.visible = false;
    }
    
    public set data(arr:string[])
    {
        let i:number;
        let len:number;
        let itemHeight:number;

        this.list.removeChildrenToPool();

        for(i = 0, len = arr.length; i < len; i++)
        {
            var item:fairygui.GComponent = this.list.addItemFromPool().asCom;
            item.getChild("txt").text = (i+1) + "." + arr[i];
            item.data = i;
            itemHeight = item.height;
        }
        this.bg.height = (itemHeight + 2) * len + 21
    }

}